<?php
/**
 * created by zzy
 * date: 2018/1/16 10:48
 */
namespace App\Eloquent\Ygt;


use Illuminate\Database\Eloquent\SoftDeletes;
class WasteBill extends DbEloquent{

    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $table    = 'ygt_waste_bill';

    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'company_id','title'=>'厂id','value'=>0,'is_must'=>1],
        ['name'=>'waste_buyer_id','title'=>'收品id','value'=>0,'is_must'=>1],
        ['name'=>'sn','title'=>'编号','value'=>'','is_must'=>1],
        ['name'=>'total_money','title'=>'金额','value'=>0,'is_must'=>1],
        ['name'=>'now_money','title'=>'金额','value'=>0,'is_must'=>1],
        ['name'=>'pay_type','title'=>'付款方式','value'=>'','is_must'=>1],
        ['name'=>'img_id','title'=>'附加图片','value'=>0,'is_must'=>0],
        ['name'=>'add_user_id','title'=>'登录出错','value'=>0,'is_must'=>1],
    ];
    //根据type不同联合的表不同
    //默认不联合表
    public static function getJoinList($where,$limit='',$offset='',$type=1,$orderby=['ygt_waste_bill.id','desc'])
    {
        switch($type)
        {
            case 1:
                $join = [
                    ['table'=>'ygt_waste_buyer','field_l'=>'ygt_waste_buyer.id','field_c'=>'=','field_r'=>'ygt_waste_bill.waste_buyer_id'],
                    ['table'=>'ygt_img_upload','field_l'=>'ygt_img_upload.id','field_c'=>'=','field_r'=>'ygt_waste_bill.img_id'],
                ];
                $column             = 'ygt_waste_bill.*';
                $column             .= ',ygt_waste_buyer.title as waste_buyer_name';
                $column             .= ',ygt_img_upload.img_url';
                break;
            default:
                $column             = 'ygt_waste_bill.*';
                $join               = '';
        }
        $groupby            = '';
        $result             = self::getList($where,$column,$limit,$offset,$orderby,$groupby,$join);
        return $result;
    }
}
